package com.agency.dao;

import java.util.List;

import javax.persistence.EntityManager;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.agency.model.Apartment;

@Repository
public class ApartmentDaoImpl implements ApartmentDao{
	
	EntityManager em;
	
	@Autowired
	private SessionFactory sf;
	
	private Session getCurrentSession(){
		return sf.getCurrentSession();
	}
	
	public void saveApartment(Apartment apt){
		getCurrentSession().save(apt);
	}
	
	@SuppressWarnings("unchecked")
	public List<Apartment> getAllApartments() {
		return getCurrentSession().createQuery("from Apartment").list();
	}

}
